package edu.cmu.cs.cs214.hw9.client.gui;

import java.awt.Color;
import java.awt.GridBagLayout;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.swing.JPanel;

import edu.cmu.cs.cs214.hw9.client.controllers.*;

/**
 * Default facelook "screen". Basically a JPanel which has the background set to the facelook blue.
 * 
 *  Also allows controllers to listen to it to watch for user interaction.
 */
public abstract class FacelookScreen extends JPanel {
	private static final long serialVersionUID = 8397197412917731760L;
	protected List<FacelookController> controllers;
	
	/**
	 * Constructs a new facelook screen.
	 */
	protected FacelookScreen() {
		setLayout(new GridBagLayout());
		setBackground(new Color(59, 89, 152));
		
		controllers = new CopyOnWriteArrayList <FacelookController>();
	}

	/**
	 * Register a new facelook controller.
	 * 
	 * @param c Controller to add.
	 */
	public void registerController(FacelookController c) {
		controllers.add(c);
	}
	
	/**
	 * Removes a facelook controller from the controllers list.
	 * 
	 * @param c Controller to remove.
	 */
	public void removeController(FacelookController c) {
		controllers.remove(c);
	}
	
	/**
	 * Tells controllers that an "event" - essentially, a user interaction - 
	 * has occured in this particular screen.
	 * 
	 * @param e Type of event that has occured.
	 */
	public void fireEventOccured(FacelookEvent e) {
		for(FacelookController c : controllers) {
			c.handleEvent(e);
		}
	}
}
